﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web.Mvc;
using System.Web;
using System.Collections.Generic;

namespace Ditto.Models
{
    [Bind(Include = "Message,SubjectID,By,Time,Type, Rating")]
    public class Comment
    {
        [Required(ErrorMessage = "Message is required")]
        [StringLength(140, ErrorMessage = "Message may not be longer than 140 characters")]
        public string Message { get; set; }

        [HiddenInput(DisplayValue = false)]
        public string By { get; set; }
        [HiddenInput(DisplayValue = false)]
        public DateTime Time { get; set; }
        [HiddenInput(DisplayValue = false)]
        public bool IsPrivate { get; set; }
        [HiddenInput(DisplayValue = false)]
        public double? Rating { get; set; }
        [HiddenInput(DisplayValue = false)]
        public object SubjectID { get; set; }
        [HiddenInput(DisplayValue = false)]
        public int ID { get; set; }
        [HiddenInput(DisplayValue = false)]
        public CommentType Type { get; set; }

        public enum CommentType { Item, User, Transaction }

        public Comment(CommentType type, object subjectID) 
        {
            this.SubjectID = subjectID;
            this.Type = type;

            this.IsPrivate = false;
        }

        public Comment() { }

        public bool IsPostedBy(string userName)
        {
            bool result = String.Equals(By, userName, StringComparison.Ordinal);
            return result;
        }
    }

    public partial class ItemComment { }

    public partial class UserComment { }

    public partial class TransactionComment { }

    public class Comments : List<Comment>
    {
        public Comment.CommentType Type { get; set; }
        public object SubjectID { get; set; }

        public Comments(Comment.CommentType type, object subjectID) { this.Type = type; this.SubjectID = subjectID; }

        public Comments(List<Comment> comments, Comment.CommentType type, object subjectID) : base(comments) { this.Type = type; this.SubjectID = subjectID; }

        public Comments() { }
    }
}